<script type="text/javascript">
    (function () {
        window.addEvent('domready', function() {
        
            $(document).getElements('.typecho-date').each(function (item) {
                item.setProperty('name', '_' + item.getProperty('name'));
                item.addEvent('change', function () {

                    $(document).getElements('.typecho-date').each(function (_item) {
                        var name = _item.name;

                        if (0 == name.indexOf('_')) {
                            _item.setProperty('name', name.slice(1));
                        }
                    });
                    
                });
                
                item.removeProperty('disabled');
            });
        
            /** 绑定按钮 */
            $(document).getElement('span.advance').addEvent('click', function () {
                Typecho.toggle('#advance-panel', this,
                '<?php _e('收起高级选项'); ?>', '<?php _e('展开高级选项'); ?>');
            });
            
            $(document).getElement('span.attach').addEvent('click', function () {
                Typecho.toggle('#upload-panel', this,
                '<?php _e('收起图片'); ?>', '<?php _e('上传图片'); ?>');
            });
            
            $('btn-save').removeProperty('disabled');
            $('btn-submit').removeProperty('disabled');
            
            $('btn-save').addEvent('click', function (e) {
				editor.sync();
                this.setProperty('disabled', true);
                this.getParent('span').addClass('loading');
                $(document).getElement('input[name=do]').set('value', 'save');
                $(document).getElement('.typecho-post-area form').submit();
            });
            
            $('btn-submit').addEvent('click', function (e) {
				editor.sync();
                this.setProperty('disabled', true);
                this.getParent('span').addClass('loading');
                $(document).getElement('input[name=do]').set('value', 'publish');

				if( $(document).getElements('.upload-progress-item input').get('value')=="" && typeof(page_product)!="undefined" ){
					
					var myTips = KindEditor.widget({
						z : 9999,
						width : 300,
						html : '没有上传任何图片！',
						css : {
								'font-size' : '24px',
								'font-weight' : 'bold',
								padding: '15px 10px',
								textAlign: 'center',
								border: '1px solid #FFD324',
								//border: '1px solid #8A1F11',
								background : '#FFF6BF',
								//background : '#FBE3E4',
								color: '#514721',
								'-moz-border-radius' : '5px',
								'-webkit-border-radius' : '5px'
						}		
					});
					setTimeout(function(){myTips.remove();},3000);

					this.getParent('span').removeClass('loading');
					$('btn-submit').removeProperty('disabled');
					return false;
					
				}else{
					
					var myTips = KindEditor.widget({
						z : 9999,
						width : 300,
						html : '数据提交中，请稍后...',
						css : {
								'font-size' : '24px',
								'font-weight' : 'bold',
								padding: '15px 10px',
								textAlign: 'center',
								border: '1px solid #FFD324',
								//border: '1px solid #8A1F11',
								background : '#FFF6BF',
								//background : '#FBE3E4',
								color: '#514721',
								'-moz-border-radius' : '5px',
								'-webkit-border-radius' : '5px'
						}	
					});					
					$(document).getElement('.typecho-post-area form').submit();
				}
            });
        });
    })();
</script>
